package params;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
/**
 * Read parameters from property file and parse them into a byte-array list
 */
class PropertyParser {
	private Properties p = null;
	public PropertyParser(){
		p = new Properties();
	}
	/**
	 * Parses the property file with a given filename
	 * @param fileName - name of property file
	 * @return list of byte arrays. Each byte array is a string constant, contained in the property file
	 */
	public LinkedList<byte[]> parse(String fileName) throws IOException{
		LinkedList<byte[]> res = new LinkedList<byte[]>();
	    p.load(new FileInputStream(fileName));
	    String str = p.getProperty("INDENT");
	    res.add(new byte[]{(byte)Integer.parseInt(str)});
	    str = p.getProperty("INDENT_SYMBOL");
	    res.add(str.getBytes());
	    str = p.getProperty("INDENT_STARTER");
	    res.add(str.getBytes());
	    str = p.getProperty("INDENT_FINISHER");
	    res.add(str.getBytes());
	    str = p.getProperty("END_OF_LINE");
	    res.add(str.getBytes());  
	    str = p.getProperty("LINE_FEED");
	    byte[] b = new byte[str.length()];
	    for(int i = 0; i < b.length; i ++){
	        b[i] = (byte) str.charAt(i);
	    }  
	    res.add(b); 
	    str = p.getProperty("SPACE");
	    res.add(str.getBytes()); 
	    str = p.getProperty("COMMENTARY_PART_1");
	    res.add(str.getBytes());
	    str = p.getProperty("COMMENTARY_PART_2");
	    res.add(str.getBytes());
	    return res;
	}
}
